Skip to content

Name identifiers like the engine (v1.0.0-beta.21) - #62

Draft
vito wants to merge 9 commits into
mainfrom
identifier-casing
Draft

vito wants to merge 9 commits into
mainfrom
identifier-casing

Conversation

@vito

@vito vito commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Port of the Dagger identifier casing work (dagger/dagger#13668) to the Python SDK. Reference implementation: dagger/dagger#14677, the in-repo version, now closed.

Release-blocking for the v1.0.0-beta.21 engine. From beta.21 the engine names modules with engine/naming instead of strcase (Python com_url → schema comURL, enum Ready → READY) and renames some core fields (shortSha → shortSHA, ...) without aliases. Without this PR, a scope generated in a beta.21 view selects names that don't exist, and calls through a module's own interfaces fail.

The gate

New naming applies when the schema has Query.formatIdentifiers and the engine is a release from v1.0.0-beta.21 on:

  • With engine: prerelease-granular API views for v1.0.0 betas dagger#14810, formatIdentifiers is served only in views ≥ beta.21, exactly where the engine names schemas by engine/naming.
  • Released beta.19 and beta.20 engines serve formatIdentifiers in every v1 view, yet still name modules by strcase. That's why the engine-version check is there too. An unreadable version (devel) leaves the decision to the schema.
  • Below the gate, everything generates byte-identical code. Tests cover this.
where how it gets names gate
scope codegen (core, clients, global client) helpers/names writes a SNAKE:UPPERCASE names file, and python -m codegen generate* -n reads it schema has formatIdentifiers and -engine (Dang's version) ≥ beta.21
module runtime (calls through the module's own interfaces, its enum members) dagger/mod/_naming.py calls Query.formatIdentifiers in the module's own session, by raw query Query.version ≥ beta.21, then a probe of formatIdentifiers (missing field → old rules)

Why codegen doesn't call formatIdentifiers

python-sdk.dang declares engineVersion = "v1.0.0-beta.18" (the SDK floor), so its view is pre-cut and Dang can't typecheck a formatIdentifiers call. A privileged-nesting exec doesn't help either: its nested client gets the caller module's view.

Following the chief's call (same as port-go), helpers/names vendors a verbatim copy of engine/naming:

  • Pin: dagger/dagger@3bae26f, on naming/4-module-naming, with K8s and K3s as terms. The pin is in helpers/names/naming/pin.go.
  • Parity: e2e:names-helper-test-check fails if the copied files differ from engine/naming at the pinned commit. It also runs TestVectors (the copy formats the engine's own testdata/vectors.json in every casing) and the helper's tests.
  • Guard: the helper prints a WARNING to stderr when a schema's version is newer than CoveredVersion (v1.0.0), the release line the copy is known to cover. It warns rather than fails: dictionary additions are rare, engine releases aren't, and failing would block every user on every new engine.
  • To bump:
    1. Copy dictionary.go, format.go, naming.go, version.go and testdata/vectors.json from engine/naming at the new commit.
    2. Set Commit in pin.go.
    3. Run go mod tidy && go test ./... in helpers/names.
    4. Raise CoveredVersion if the commit is on a newer release line.
  • ⚠️ The pin needs a refresh to whatever engine/naming commit finally lands on dagger/dagger main.

What changes in generated code (beta.21 views only)

  • Methods get the engine's snake_case name (prerequisite_shas, experimental_with_all_gpus). When the legacy converter gave a different name (prerequisite_sh_as), it stays as a deprecated method that warns and forwards.
  • Core enums become ValueEnum (a new subclass of dagger.client.base.Enum), with SCREAMING_SNAKE members:
    • Each member holds the schema value it stands for, and is sent by value.
    • The schema's other spellings stay as deprecated aliases: ImageMediaTypes.OCIMediaTypes is ImageMediaTypes.OCI.
    • Defaults use the canonical member.
  • Dependency-module enums whose @enumValue holds the module's own values stay plain Enums, unchanged.
  • Input fields whose GraphQL name snake_to_camel can't derive (call_id → callID) go through the existing _graphql_names table.

Generated entrypoints: dang.toml

dagger/dagger#14812 reads [imports.Dagger] dagger from a dang.toml next to the entrypoint, and serves an entrypoint without one at v1.0.0-beta.20. The entrypoint generated into a module (sdk/entrypoint/) now ships one:

dang = "2.1"

[imports.Dagger]
dagger = "<version>"
module version
has sdk/entrypoint/dang.toml kept byte for byte; its dagger (or beta.20 if absent / true)
freshly initialized (no config before) the running engine's version, minus build metadata
moving onto the entrypoint from a runtime whose manifest declares ≥ beta.21 that version
anything else (existing entrypoint without dang.toml, older runtime manifests) v1.0.0-beta.20, so regenerating never silently changes its naming

The scope is generated in that version's view, so bindings and calls agree.

  • Shared entrypoint: entrypoint/, the remote one, ships no dang.toml. It stays at beta.20, and so do its modules' scopes (core-schema's v1.0.0-0 maps to the same pre-cut view).
  • Runtime-mode modules: new ones (--legacy-runtime) keep engineVersion = core-schema's v1.0.0-0, i.e. pre-cut. That's the compatibility path; it's left alone here.
  • FunctionCachePolicy: the old spellings (Never/PerSession/Default) are kept. Per final core: rename non-canonical core names from beta.21 dagger#14681 they stay valid in every view, so no version-dependent emission.

Breaking changes (for users who opt into a beta.21 view)

  1. A core enum's .name changes. A member found through a deprecated alias resolves to the canonical member: ImageMediaTypes.OCIMediaTypes.name == "OCI". .value and what goes over the wire don't change.
  2. Core enum classes extend ValueEnum instead of Enum.
  3. Renamed values with no alias in the schema are gone from the bindings. The schema doesn't show the old names (shortSha, FunctionCachePolicy.PerSession as a distinct member in post-cut views, ...), and the #14677 "renamed core names" tables are intentionally not ported. Python method names mostly don't change (short_sha either way).
  4. Deprecated, still working: old method names (prerequisite_sh_as) and enum spellings emit DeprecationWarning.
  5. A module's own API is renamed by the engine for modules on ≥ beta.21 (com_url → comURL). New modules get this by default through their dang.toml.

Dependencies

This PR must ship with or after those engine changes.

Follow-ups / open questions

  • Dependency clients across the cut. scope.dang (clientSchema) reads a dependency client's schema with member.source.withEngineVersion(view).clientSchemaIntrospectionJSON. Under #14669 that also changes the dependency's naming rules, so a client can disagree with what the engine serves across the beta.21 cut. It needs the upcoming clientSchemaIntrospectionJSON(view:) engine argument, from a sibling dagger/dagger PR.
  • dang.toml lives in generated output. It sits in sdk/entrypoint/, inside the sdk/ tree generation rewrites. It's kept across generations, but a user who deletes sdk/ and regenerates drops back to beta.20 (pre-cut naming). A module-root dang.toml would avoid that; this PR follows the spec of writing it next to the entrypoint.
  • Runtime cost. Modules that declare interfaces make a few extra queries per call to resolve names (version, probe, one batch per casing). They could be folded into one aliased query.

Testing

  • Unit:
    • go test ./... and go vet in helpers/names: vectors, gate, engine gate, K8s term, SCREAMING_SNAKE = uppercased snake.
    • e2e:sdk-test-check (603 passed): new tests/codegen/test_names.py and tests/mod/test_naming.py cover both gates, names on/off, ValueEnum, aliases, packages, the global client, the CLI, interface call names, enum args/results, and the version gate.
    • ruff check and ruff format --check on sdk/.
  • e2e, on the sandbox's stock engine: names-helper-test-check, entrypoint-version-check (new), static-scope-init-check, generate-scope-view-check, generate-scope-clients-check, generate-scope-global-client-check, generate-scope-plain-check, mod-generate-clients-check, entrypoint-kind-check.
  • Not run: anything against a dev engine built from the stacked dagger branches. That leaves the post-cut path end to end unverified: actual formatIdentifiers responses, generated core at a beta.21 view, interface calls in a beta.21 module, and #14812 reading the dang.toml. The full e2e suite and engine-e2e:* weren't run either.

vito added 9 commits October 22, 2026 16:31
The Python code generator needs a schema's names in snake_case as the engine
formats them, but generation reads schemas from introspection JSON and
python-sdk itself is served before v1.0.0-beta.21, where
Query.formatIdentifiers lives, so it can't ask the engine.

helpers/names writes the names file (SNAKE:UPPERCASE map) with a verbatim
copy of dagger/dagger's engine/naming at a pinned commit (naming/pin.go),
keyed by the schema's __schemaVersion like formatIdentifiers(version:). A
schema without Query.formatIdentifiers gets an empty file: that's the gate.
It warns when a schema is newer than the release line the copy covers, and
tests the copy against the engine's own vectors.

Signed-off-by: Alex Suraci <alex@dagger.io>
Every generate command takes a names file (-n, as helpers/names writes it).
For a schema with Query.formatIdentifiers (v1.0.0-beta.21 views), names come
from it; schemas without it, and names missing from it, keep the legacy
converter and generate byte-identical code.

With the engine's names:

- A method whose legacy-converted name differs (prerequisite_sh_as) keeps
  it as a deprecated alias.
- Core enums extend the new ValueEnum: SCREAMING_SNAKE members holding the
  schema value they stand for, sent by value; the schema's other spellings
  (OCIMediaTypes) are deprecated aliases, and defaults use the canonical
  member.
- A dependency module's enum whose @enumValue holds its own values stays a
  plain Enum, as before.

Signed-off-by: Alex Suraci <alex@dagger.io>
From v1.0.0-beta.21 the engine names a module's declarations by its naming
rules (get_url is getURL, Ready is READY), so the calls the runtime builds
through the module's own interfaces must use those names.

Before invoking a function of a module that declares interfaces, the
runtime asks Query.formatIdentifiers, in batches, by raw query since the SDK
files can't import bindings. The API being in the session's schema is the
gate: the session is served in the module's view, so older modules keep the
plain conversion. Interface arguments are now bound by their Python name.

Signed-off-by: Alex Suraci <alex@dagger.io>
The engine reads `[imports.Dagger] dagger` from a dang.toml beside an
entrypoint (dagger/dagger#14812) and serves it at v1.0.0-beta.20 without
one. The entrypoint generated into a module now ships one, and the scope is
generated in that version's view, so bindings and calls agree.

A new module declares the engine it is created on, without build metadata,
and so gets the engine's naming from beta.21. A module that already had an
entrypoint but no dang.toml gets beta.20, what the engine already serves it,
so regenerating never moves it silently. An existing dang.toml is kept.

FunctionCachePolicy keeps its old spellings: they stay valid in every view.

Signed-off-by: Alex Suraci <alex@dagger.io>
namesHelperTestCheck refuses a copy of engine/naming that differs from the
pinned commit and runs the helper's tests. entrypointVersionCheck covers
the version a generated entrypoint declares: new, existing without a
dang.toml, and the module's own dang.toml.

Signed-off-by: Alex Suraci <alex@dagger.io>
Core, each client and the global client are generated with the names file
helpers/names writes from their schemas, so a scope read in a
v1.0.0-beta.21 view gets the engine's names; any other gets an empty file
and the code it always had.

Signed-off-by: Alex Suraci <alex@dagger.io>
Re-pin the copy of engine/naming to dagger/dagger 3bae26f, where K8s and K3s
are terms of their own.

Released engines before v1.0.0-beta.21 (beta.19, beta.20) serve
Query.formatIdentifiers in every v1 view but still name modules by their
legacy rules, so the schema alone is not a sufficient gate there. The
helper now takes the engine's version (-engine) and writes no names for a
release before the cut; scope.dang passes it.

Signed-off-by: Alex Suraci <alex@dagger.io>
The runtime's gate also checks Query.version: released engines before
v1.0.0-beta.21 serve formatIdentifiers but name modules by their legacy
rules.

Calls through a module's own interfaces that return its enums (or lists of
them) now read the members by the names the engine gave them (READY for
Ready), the reverse of how they're sent.

Signed-off-by: Alex Suraci <alex@dagger.io>
A module moving onto the generated entrypoint from a runtime whose
manifest declares v1.0.0-beta.21 or later was already named by the engine's
rules: its dang.toml declares that version rather than beta.20, so its code
keeps working.

Signed-off-by: Alex Suraci <alex@dagger.io>
@vito vito mentioned this pull request Oct 30, 2026
1 task
@eunomie

eunomie commented Nov 13, 2026

Copy link
Copy Markdown
Member

@vito I think we can close this one in favor of #72, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants